<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 

      https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=33985,31253,33848,33675,33607,26350&wd=dses&req=2&bs=%E8%9B%8B%E6%B0%A8%E9%85%B8%E7%9A%84%E7%BC%A9%E5%86%99&pbs=%E8%9B%8B%E6%B0%A8%E9%85%B8%E7%9A%84%E7%BC%A9%E5%86%99&csor=4&pwd=dse&cb=show


   -->
  <script>
    function jsonp({
      url,
      params,
      cb
    }) {
      return new Promise((resolve, reject) => {
        let script = document.createElement('script');
        window[cb] = function (data) {
          resolve(data);
          document.body.removeChild(script);
        };

        const arr = [];
        params = {
          ...params,
          cb
        }

        for (let key in params) {
          arr.push(`${key}=${params[key]}`)
        }

        script.src = `${url}?${arr.join('&')}`;
        document.body.appendChild(script);
      })
    }
    jsonp({
      url: 'http://localhost:3000/say',
      params: {
        pre: '1',
        p: 3,
        ie: 'utf-8',
        json: '1',
        prod: 'pc',
        from: 'pc_web',
        csor: '4',
        pwd: '爱你'
      },
      cb: 'show'
    }).then((data) => {
      console.log(data);
    })
  </script>
</body>

</html>